<?
/*
 * an example of how to use PHP with MGIP
 */

$client = new SoapClient(null, array('location' => "http://mgip2.biology.gatech.edu/api/apiServer.php",
                                     'uri'      => "http://mgip2.biology.gatech.edu/api",
                                     'trace'    => true));
try {
  $client->setupUser("cdc","cdc");
  
  $organism=$client->getOrganisms();
  // find influenza
  $influenzaId=0;
  for($i=0;$i<count($organism);$i++){
    if($organism[$i][scientificName]=="Orthomyxoviridae influenza"){
      $influenzaId=$organism[$i][id];
    }
  }
  
  // switch to flu
  $client->changeCurrentOrganism($influenzaId);
  echo "\n";
  
  $locus=$client->getLoci(false);
  $locusId=$locus[flu1][id];
  
  // get together the locus data
  $data['trace_1']=getBinaryContents("traceFiles/1.ab1");
  $data['trace_2']=getBinaryContents("traceFiles/2.ab1");
  $response=$client->processBinaryTraces($locusId,$data);
  //print_r($response[blast]);
  //print_r($response[phrap]);
  //print_r($response['phrap']['qualFile']);
  print_r($response['results']);
  //print_r(array_keys($response));
} catch (Exception $e) {
  echo "Failure!\n";
  echo $e; 
  echo '<hr>';
  //echo $client->__getLastRequest() . '<hr>' . $client->__getLastRequestHeaders() . '<hr>' .$client->__getLastResponse() . '<hr>' . $client->__getLastResponseHeaders();
}
function getBinaryContents($filename){
  return base64_encode(file_get_contents($filename));
}
?>  